package umlTool;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * represents an abstract member in a class
 * 
 * @author Mimo
 * 
 */
public abstract class ClassMember implements ISaveable, ICommentable {
	protected String name;
	protected String type;
	protected AccessModifiers access;
	protected Boolean Static;
	protected Boolean Final;
	protected String comment;

	public ClassMember() {
		Static = Final = false;
	}

	public ClassMember(Element elem) {
		name = elem.getAttribute("name");
		type = elem.getAttribute("type");
		access = AccessModifiers.valueOf(elem.getAttribute("accessMod"));
		Static = Boolean.parseBoolean(elem.getAttribute("static"));
		Final = Boolean.parseBoolean(elem.getAttribute("final"));
		comment = elem.getAttribute("comment");
	}

	public Element saveToXml(Document doc) {
		Element elem = doc.createElement(classType());

		elem.setAttribute("name", name);
		elem.setAttribute("type", type);
		elem.setAttribute("accessMod", access.toString());
		elem.setAttribute("static", Static.toString());
		elem.setAttribute("final", Final.toString());
		elem.setAttribute("comment", comment);
		return elem;
	}

	public abstract String classType();

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setAccess(AccessModifiers access) {
		this.access = access;
	}

	AccessModifiers getAccess() {
		return access;
	}

	public void setType(String type) {
		this.type = type;
	}

	String getType() {
		return type;
	}

	public void setStatic(Boolean _static) {
		Static = _static;
	}

	Boolean getStatic() {
		return Static;
	}

	public void setFinal(Boolean _final) {
		Final = _final;
	}

	Boolean getFinal() {
		return Final;
	}
}
